﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using NetROS.Tiers.Entities;
using NetROS.Tiers.Data;

#endregion

namespace NetROS.Tiers.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="VwArtiklStanjeVPCProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class VwArtiklStanjeVPCProviderBaseCore : EntityViewProviderBase<VwArtiklStanjeVPC>
	{
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;VwArtiklStanjeVPC&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;VwArtiklStanjeVPC&gt;"/></returns>
		protected static VList&lt;VwArtiklStanjeVPC&gt; Fill(DataSet dataSet, VList<VwArtiklStanjeVPC> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<VwArtiklStanjeVPC>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;VwArtiklStanjeVPC&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<VwArtiklStanjeVPC>"/></returns>
		protected static VList&lt;VwArtiklStanjeVPC&gt; Fill(DataTable dataTable, VList<VwArtiklStanjeVPC> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					VwArtiklStanjeVPC c = new VwArtiklStanjeVPC();
					c.IDArtikl = (Convert.IsDBNull(row["IDArtikl"]))?(int)0:(System.Int32?)row["IDArtikl"];
					c.IDOrganizacijaOd = (Convert.IsDBNull(row["IDOrganizacijaOd"]))?(int)0:(System.Int32?)row["IDOrganizacijaOd"];
					c.Vrijednost2 = (Convert.IsDBNull(row["Vrijednost2"]))?0:(System.Decimal?)row["Vrijednost2"];
					c.MPC = (Convert.IsDBNull(row["MPC"]))?0.0F:(System.Single?)row["MPC"];
					c.Datum = (Convert.IsDBNull(row["Datum"]))?DateTime.MinValue:(System.DateTime?)row["Datum"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;VwArtiklStanjeVPC&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;VwArtiklStanjeVPC&gt;"/></returns>
		protected VList<VwArtiklStanjeVPC> Fill(IDataReader reader, VList<VwArtiklStanjeVPC> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					VwArtiklStanjeVPC entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<VwArtiklStanjeVPC>("VwArtiklStanjeVPC",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new VwArtiklStanjeVPC();
					}
					entity.IDArtikl = reader.IsDBNull(reader.GetOrdinal("IDArtikl")) ? null : (System.Int32?)reader["IDArtikl"];
					//entity.IDArtikl = (Convert.IsDBNull(reader["IDArtikl"]))?(int)0:(System.Int32?)reader["IDArtikl"];
					entity.IDOrganizacijaOd = reader.IsDBNull(reader.GetOrdinal("IDOrganizacijaOd")) ? null : (System.Int32?)reader["IDOrganizacijaOd"];
					//entity.IDOrganizacijaOd = (Convert.IsDBNull(reader["IDOrganizacijaOd"]))?(int)0:(System.Int32?)reader["IDOrganizacijaOd"];
					entity.Vrijednost2 = reader.IsDBNull(reader.GetOrdinal("Vrijednost2")) ? null : (System.Decimal?)reader["Vrijednost2"];
					//entity.Vrijednost2 = (Convert.IsDBNull(reader["Vrijednost2"]))?0:(System.Decimal?)reader["Vrijednost2"];
					entity.MPC = reader.IsDBNull(reader.GetOrdinal("MPC")) ? null : (System.Single?)reader["MPC"];
					//entity.MPC = (Convert.IsDBNull(reader["MPC"]))?0.0F:(System.Single?)reader["MPC"];
					entity.Datum = reader.IsDBNull(reader.GetOrdinal("Datum")) ? null : (System.DateTime?)reader["Datum"];
					//entity.Datum = (Convert.IsDBNull(reader["Datum"]))?DateTime.MinValue:(System.DateTime?)reader["Datum"];
					entity.AcceptChanges();
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="VwArtiklStanjeVPC"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="VwArtiklStanjeVPC"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, VwArtiklStanjeVPC entity)
		{
			reader.Read();
			entity.IDArtikl = reader.IsDBNull(reader.GetOrdinal("IDArtikl")) ? null : (System.Int32?)reader["IDArtikl"];
			//entity.IDArtikl = (Convert.IsDBNull(reader["IDArtikl"]))?(int)0:(System.Int32?)reader["IDArtikl"];
			entity.IDOrganizacijaOd = reader.IsDBNull(reader.GetOrdinal("IDOrganizacijaOd")) ? null : (System.Int32?)reader["IDOrganizacijaOd"];
			//entity.IDOrganizacijaOd = (Convert.IsDBNull(reader["IDOrganizacijaOd"]))?(int)0:(System.Int32?)reader["IDOrganizacijaOd"];
			entity.Vrijednost2 = reader.IsDBNull(reader.GetOrdinal("Vrijednost2")) ? null : (System.Decimal?)reader["Vrijednost2"];
			//entity.Vrijednost2 = (Convert.IsDBNull(reader["Vrijednost2"]))?0:(System.Decimal?)reader["Vrijednost2"];
			entity.MPC = reader.IsDBNull(reader.GetOrdinal("MPC")) ? null : (System.Single?)reader["MPC"];
			//entity.MPC = (Convert.IsDBNull(reader["MPC"]))?0.0F:(System.Single?)reader["MPC"];
			entity.Datum = reader.IsDBNull(reader.GetOrdinal("Datum")) ? null : (System.DateTime?)reader["Datum"];
			//entity.Datum = (Convert.IsDBNull(reader["Datum"]))?DateTime.MinValue:(System.DateTime?)reader["Datum"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="VwArtiklStanjeVPC"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="VwArtiklStanjeVPC"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, VwArtiklStanjeVPC entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.IDArtikl = (Convert.IsDBNull(dataRow["IDArtikl"]))?(int)0:(System.Int32?)dataRow["IDArtikl"];
			entity.IDOrganizacijaOd = (Convert.IsDBNull(dataRow["IDOrganizacijaOd"]))?(int)0:(System.Int32?)dataRow["IDOrganizacijaOd"];
			entity.Vrijednost2 = (Convert.IsDBNull(dataRow["Vrijednost2"]))?0:(System.Decimal?)dataRow["Vrijednost2"];
			entity.MPC = (Convert.IsDBNull(dataRow["MPC"]))?0.0F:(System.Single?)dataRow["MPC"];
			entity.Datum = (Convert.IsDBNull(dataRow["Datum"]))?DateTime.MinValue:(System.DateTime?)dataRow["Datum"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region VwArtiklStanjeVPCFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwArtiklStanjeVPC"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwArtiklStanjeVPCFilterBuilder : SqlFilterBuilder<VwArtiklStanjeVPCColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwArtiklStanjeVPCFilterBuilder class.
		/// </summary>
		public VwArtiklStanjeVPCFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwArtiklStanjeVPCFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwArtiklStanjeVPCFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwArtiklStanjeVPCFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwArtiklStanjeVPCFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwArtiklStanjeVPCFilterBuilder

	#region VwArtiklStanjeVPCParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwArtiklStanjeVPC"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwArtiklStanjeVPCParameterBuilder : ParameterizedSqlFilterBuilder<VwArtiklStanjeVPCColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwArtiklStanjeVPCParameterBuilder class.
		/// </summary>
		public VwArtiklStanjeVPCParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwArtiklStanjeVPCParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwArtiklStanjeVPCParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwArtiklStanjeVPCParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwArtiklStanjeVPCParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwArtiklStanjeVPCParameterBuilder
} // end namespace
